import type { TreeDataNode } from 'antd';
import type { Object3D } from 'three/webgpu';

const generateData = (object: Object3D): TreeDataNode => {
  const key = object.uuid;
  const children: TreeDataNode[] = [];
  const title = object.name;
  object.children.forEach((child) => {
    children.push(generateData(child));
  });
  return { key, title, children };
};

const getAncestorsKeys = (object: Object3D) => {
  const ancestorsKeys = [object.uuid];
  object.traverseAncestors((anc) => {
    ancestorsKeys.push(anc.uuid);
  });
  return ancestorsKeys;
};

export { generateData, getAncestorsKeys };
